import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class hive {
    private static String driverName = "org.apache.hive.jdbc.HiveDriver";

    public static void main(String[] args) throws Exception {
        System.out.printf("HiveDriver");
        Class.forName(driverName);
        Connection con = DriverManager.getConnection("jdbc:hive2://localhost:10000/zwctest", "hive", "");
        Statement stmt = con.createStatement();
//
//        for (int i=0;i<=100;i++){
//            boolean execute = stmt.execute("INSERT INTO test (id) VALUES (4)");
//            System.out.println(execute);
//        }

        // boolean execute = stmt.execute("INSERT INTO zwctest.test (id) VALUES (1111)");
        // boolean execute = stmt.execute("INSERT INTO test (id) VALUES (1111)");
        //String sql = "select * from test";
        long q = System.currentTimeMillis();
        String sql = "SELECT sum(id) from test";
        ResultSet res = stmt.executeQuery(sql);
        while (res.next()) {
            System.out.println(String.valueOf(res.getInt(1)));
        }
        long q1 = System.currentTimeMillis();
        System.out.println((q1 - q) / 1000);
        System.out.println("Database userdb created successfully.");

        con.close();
    }
}

